package leetcode;

/**
 * @author Liangyaoyun
 */
public class TheSquareRootOfX {
    public int mySqrt(int x) {
        if(x==1){
            return 1;
        }else if(x==0){
            return 0;
        }
        int  start = 1;
        int  end = x / 2;
        while (start < end) {
            //防止start-end=0的情况
            int mid = start + (end - start+1) / 2;
            if (mid>x/mid) {
                end = mid - 1;

            } else  {
                start = mid;
            }
        }
        return start;
    }
}
